#include "AgentManager.h"

AgentManager::AgentManager()
{
	sessions = new std::map<int,std::map<std::string,int>*>;
	
}

AgentManager::~AgentManager()
{
	delete sessions;
}

void AgentManager::setPool(DataPool *_pool) {
	pool = _pool;
}

	void AgentManager::registerBehaviour(AgentBehaviour *behaviour) {
		int key = ++counter;
		std::map<std::string,int> *session = new std::map<std::string,int>;
		sessions->insert(std::pair<int,std::map<std::string,int>*>(key,session));
		behaviour->setAgentId(key);
	}
	void AgentManager::execute(AgentBehaviour *behaviour,std::string key) {

		
		AttributeHolder *attribs = new AttributeHolder(getSession(behaviour->getAgentId()));

		attribs->setPool(pool);
		
		behaviour->select(attribs,key);
		
		behaviour->getAction()->execute(attribs);
	}


	std::map<std::string,int>* AgentManager::getSession(int agent) {
		std::map<int,std::map<std::string,int> * >::iterator it;
		it = sessions->find(agent);
		return it->second;
	}
	
	